import { isMobile, isPhone, isURL, validateSocialCreditCode, isEmail, validateFileList } from '@/util/validate'


export const userOption = function () {
  return {
    labelWidth: 140,
      submitBtn: true,
      emptyBtn: true,
      submitText: '提交',
      column: [
        {
          label: '供应商名称',
          prop: 'supplierName',
          type: 'input',
          props: { label: 'supplierName', value: 'id' },
          maxlength: 100,
          span: 8,
          rules: [{ required: true, message: '请输入供应商名称', trigger: 'blur' }]
        },
        {
          label: '供应商简称',
          prop: 'supplierShortName',
          type: 'input',
          props: { label: 'supplierShortName', value: 'id' },
          span: 8,
          maxlength: 100
        },
        {
          label: '成立日期',
          prop: 'establishDate',
          type: 'date',
          span: 8,
          format: 'yyyy-MM-dd',
          valueFormat: 'yyyy-MM-dd',
          rules: [{ required: true, message: '请选择成立日期', trigger: 'blur' }]
        },
        {
          label: '境内外关系',
          prop: 'outbound',
          type: 'select',
          dicData: [
            { label: '境内', value: 0 },
            { label: '境外', value: 1 }
          ],
          span: 8,
          rules: [{ required: true, message: '请选择境内外关系', trigger: 'change' }]
        },
        {
          label: '统一社会信用代码',
          prop: 'socialCreditCode',
          type: 'input',
          props: { label: 'socialCreditCode', value: 'socialCreditCode' },
          span: 8,
          rules: [
            {
              required: true,
              validator: (_, v, c) =>
                c(
                  !v
                    ? c(new Error('请输入统一社会信用代码'))
                    : !validateSocialCreditCode(v)
                    ? c(new Error('统一社会信用代码格式不正确'))
                    : c()
                ),
              trigger: 'blur'
            }
          ]
        },
        {
          label: '境外识别码',
          maxlength: 50,
          span: 8,
          prop: 'outsideIdentifier',
          display: false
        },
        {
          label: '集团名称',
          prop: 'groupName',
          type: 'input',
          maxlength: 50,
          props: { label: 'companyName', value: 'companyName' },
          span: 8
        },
        {
          label: '公司类型',
          prop: 'companyType',
          type: 'select',
          dicData: [
            { label: '无限公司', value: '0' },
            { label: '有限责任公司', value: '1' },
            { label: '两合公司', value: '2' },
            { label: '股份有限公司', value: '3' },
            { label: '股份两合公司', value: '4' }
          ],
          span: 8,
          rules: [{ required: true, message: '请选择公司类型', trigger: 'change' }]
        },
        {
          label: '所属行业',
          prop: 'capitalType',
          type: 'select',
          dicData: [
            { label: '国有企业', value: '0' },
            { label: '民营企业', value: '1' },
            { label: '中外合资', value: '2' },
            { label: '外商独资', value: '3' },
            { label: '上市公司', value: '4' }
          ],
          span: 8,
          rules: [{ required: true, message: '请选择所属行业', trigger: 'change' }]
        },
        {
          label: '公司网址',
          prop: 'website',
          type: 'input',
          props: { label: 'url', value: 'url' },
          span: 8,
          rules: [
            {
              validator: (_, v, c) => c(v && !isURL(v) ? c(new Error('公司网址格式不正确')) : c()),
              trigger: 'blur'
            }
          ]
        },
        {
          label: '区域',
          span: 8,
          prop: 'areas',
          type: 'cascader',
          props: {
            label: 'label',
            value: 'value',
            children: 'children'
          },
          dicData: window.getRegionData(),
          rules: [
            {
              required: true,
              message: '请输入区域',
              trigger: 'change'
            }
          ]
        },
        {
          label: '注册地址',
          prop: 'registerAddr',
          type: 'input',
          props: { label: 'registerAddr', value: 'registerAddr' },
          span: 8,
          rules: [{ required: true, message: '请选择注册地址', trigger: 'blur' }]
        },
        {
          label: '联系人',
          prop: 'contact',
          type: 'input',
          props: { label: 'contact', value: 'contact' },
          span: 8,
          rules: [{ required: true, message: '请输入联系人', trigger: 'blur' }]
        },
        {
          label: '联系人职务',
          prop: 'contactPost',
          type: 'input',
          props: { label: 'contactPost', value: 'contactPost' },
          span: 8
        },
        {
          label: '手机号码',
          prop: 'phone',
          type: 'input',
          props: { label: 'phone', value: 'phone' },
          span: 8,
          rules: [
            {
              required: true,
              trigger: 'blur',
              validator: (_, v, c) =>
                c(!v ? c(new Error('请输入手机号码')) : !isMobile(v) ? c(new Error('手机号格式不正确')) : c())
            }
          ]
        },
        {
          label: '邮箱',
          prop: 'email',
          type: 'input',
          props: { label: 'email', value: 'email' },
          span: 8,
          rules: [
            {
              required: true,
              trigger: 'blur',
              validator: (_, v, c) =>
                c(!v ? c(new Error('请输入邮箱')) : !isEmail(v) ? c(new Error('邮箱格式不正确')) : c())
            }
          ]
        },
        {
          label: '固定电话',
          prop: 'telephone',
          type: 'input',
          props: { label: 'telephone', value: 'telephone' },
          rules: [
            {
              required: false,
              trigger: 'blur',
              validator: (_, v, c) => c(v && !isPhone(v) ? c(new Error('固定电话不正确')) : c())
            }
          ],
          span: 8
        },
        {
          label: '厂房面积',
          prop: 'plantArea',
          type: 'number',
          controls: false,
          props: { label: 'factoryArea', value: 'factoryArea' },
          span: 8
        },
        {
          label: '营业执照',
          prop: 'busLicense',
          type: 'upload',
          span: 24,
          slot: true,
          rules: [
            {
              required: true,
              message: '请上传营业执照',
              validator: validateFileList,
              trigger: 'blur'
            }
          ]
          // propsHttp: { res: 'data' },
          // tip: '只能上传jpg/png/pdf文件，最多上传5个文件，且单个文件大小不超过500kb',
          // action: '/imgupload'
        }
      ]
  }
}